package com.infonautics.action;


import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import com.common.Sql_changes;
import com.hibernate.Userinfo;
import com.infonautics.dao.IUserinfoDao;
import com.infonautics.dao.imp.IUserinfoDaoImp;
import com.opensymphony.xwork2.ActionSupport;
import com.system.dao.ISystemDao;

public class LoginAction extends ActionSupport implements SessionAware{
	private static final long serialVersionUID = 1L;
	private Map<String,Object> session;
	private IUserinfoDao sysmanagerDao = new IUserinfoDaoImp();
	private ISystemDao<Userinfo> sysmaDao = new IUserinfoDaoImp();
	private String username;
	private String password;
	private String passes;
	private String errormessage;
	private Userinfo userinfo;
	
	public String login()throws Exception{	 
		username = Sql_changes.sql_Infusion(username);
		password = Sql_changes.sql_Infusion(password);
		userinfo = sysmanagerDao.doLogin(username, password);	
		if(userinfo != null){			
			session.put("userinfo", userinfo);			
			return "infonautics";			
		}else{
			errormessage = "您的用户名或密码错误,请重新输入";
			return "error";
		}
	}
	//退出
	public String out()throws Exception{
		session.remove("userinfo");
		return "logout";
	}
	//修改个人信息页面
	public String uppassPage(){
		if(session.get("userinfo")!=null){
			userinfo = (Userinfo)session.get("userinfo");
			passes = userinfo.getPassword();
		}
		return "uppassPage";
	}
	//修改个人信息
	public String uppass() throws Exception{
		if(session.get("userinfo")!=null){
			userinfo = (Userinfo)session.get("userinfo");
			userinfo.setPassword(password);
			sysmaDao.doModfiy(userinfo);
		}
		return "uppass";
	}
	public Map<String, Object> getSession() {
		return session;
	}
	
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getErrormessage() {
		return errormessage;
	}
	
	public void setErrormessage(String errormessage) {
		this.errormessage = errormessage;
	}
	
	public Userinfo getUserinfo() {
		return userinfo;
	}
	
	public void setUserinfo(Userinfo userinfo) {
		this.userinfo = userinfo;
	}
	
	public String getPasses() {
		return passes;
	}
	
	public void setPasses(String passes) {
		this.passes = passes;
	}

	

}
